<?php

function mydownloads_feednew($limit=0, $offset=0)
{
	global $xoopsDB;

	$myts =& MyTextSanitizer::getInstance();

	$dirname = basename( dirname( dirname( __FILE__ ) ) );
	$URL_MOD = XOOPS_URL."/modules/".$dirname;

	if (isset($_GET['cid'])) { 
	$categoryid = intval($_GET['cid']);
	$sql = "SELECT d.lid, d.title as dtitle, d.date, d.cid, d.submitter, d.hits, t.description, c.title as ctitle FROM ".$xoopsDB->prefix("mydownloads_downloads")." d, ".$xoopsDB->prefix("mydownloads_text")." t, ".$xoopsDB->prefix("mydownloads_cat")." c WHERE d.cid= ".$categoryid." AND t.lid=d.lid AND d.cid=c.cid AND d.status>0 ORDER BY d.date DESC";
	}
	else {
	$sql = "SELECT d.lid, d.title as dtitle, d.date, d.cid, d.submitter, d.hits, t.description, c.title as ctitle FROM ".$xoopsDB->prefix("mydownloads_downloads")." d, ".$xoopsDB->prefix("mydownloads_text")." t, ".$xoopsDB->prefix("mydownloads_cat")." c WHERE t.lid=d.lid AND d.cid=c.cid AND d.status>0 ORDER BY d.date DESC";
	}


	$result = $xoopsDB->query($sql, $limit, $offset);



	$i = 0;
	$ret = array();

 	while( $row = $xoopsDB->fetchArray($result) )
 	{
 		$lid = $row['lid'];
		$ret[$i]['link']     = $URL_MOD."/singlefile.php?lid=".$lid;
		$ret[$i]['cat_link'] = $URL_MOD."/viewcat.php?cid=".$row['cid'];

		$ret[$i]['title'] = $row['dtitle'];
		$ret[$i]['time']  = $row['date'];

// atom feed
		$ret[$i]['id'] = $lid;
		$ret[$i]['description'] = $myts->makeTareaData4Show( $row['description'], 0 );	//no html

// category
		$ret[$i]['cat_name'] = $row['ctitle'];

// counter
		$ret[$i]['hits'] = $row['hits'];

// this module dont show user name
//		$ret[$i]['uid'] = $row['submitter'];

		$i++;
	}

	return $ret;
}


?>